﻿using System.Collections.Generic;
using System.Reflection;
using Antlr.Runtime;
using NHibernate.Hql.Ast.ANTLR;

namespace HQLAddin.Util
{
	public static class ParserErrorHandlerExtensions
	{
		private static readonly FieldInfo ExceptionList = typeof(IErrorReporter).Assembly
			.GetType("NHibernate.Hql.Ast.ANTLR.ErrorCounter")
			.GetField("_recognitionExceptions", BindingFlags.NonPublic | BindingFlags.Instance);

		public static IEnumerable<RecognitionException> GetExceptions(this IParseErrorHandler peh)
		{
			return (IEnumerable<RecognitionException>) ExceptionList.GetValue(peh);
		}
	}
}